package com.wellsoft.mobileoa.utils.widget;

import java.util.ArrayList;
import java.util.List;

import android.graphics.Rect;
import android.text.method.ScrollingMovementMethod;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.wellsoft.mobileoa.R;
import com.wellsoft.mobileoa.utils.BaseActivity;
import com.wellsoft.mobileoa.utils.BaseView;
import com.wellsoft.mobileoa.utils.BaseWidget;
import com.wellsoft.mobileoa.utils.SystemConfig;
import com.wellsoft.mobileoa.wsmodel.WSOA_PageField;
import com.wellsoft.mobileoa.wsmodel.WSOA_PostField;
import com.wmobile.ui.AutoResizeTextView;

public class TextWidget extends BaseWidget {
	public TextView fieldTitleTv;
	public TextView fieldValueTv;

	public TextWidget(WSOA_PageField field, BaseView baseView) {
		this.field = field;
		this.baseView = baseView;
	}

	@Override
	public View getView() {
		if (SystemConfig.stringIsNullOrEmpty(field.getFieldTitle())) {
			view = LayoutInflater.from(baseView.getBaseActivity()).inflate(
					R.layout.textviewwidget, null);
			fieldValueTv = (TextView) view
					.findViewById(R.id.textwidget_fieldvaluetv);
			fieldValueTv.setText(field.getFieldValue());
		} else {
			view = LayoutInflater.from(baseView.getBaseActivity()).inflate(
					R.layout.textwidget, null);
			fieldTitleTv = (TextView) view
					.findViewById(R.id.textwidget_fieldtitletv);
			fieldValueTv = (TextView) view
					.findViewById(R.id.textwidget_fieldvaluetv);
			fieldTitleTv.setText(field.getFieldTitle());
			fieldValueTv.setText(field.getFieldValue());
		}
		return view;
	}

	@Override
	public WSOA_PostField getValue() {
		WSOA_PostField postfield = new WSOA_PostField();
		postfield.setFieldName(field.getFieldName());
		ArrayList<String> listValue = new ArrayList<String>();
		listValue.add(field.getFieldValue());
		postfield.setFieldValues(listValue);

		return postfield;
	}

}
